<!-- 风险对象 -->
<template>
  <div class="dual_prevention_div" v-loading="tableLoading" element-loading-text="数据加载中">
    <div class="dual_prevention_query_div">
      <el-form :model="searchForm" :inline="true" size="small">
        <el-form-item label="" label-width="0">
          <el-input v-model="searchForm.work_code" placeholder="请输入编号" clearable
            @clear="currentPage = 1; inquiry()"></el-input>
        </el-form-item>
        <el-form-item label="" label-width="0">
          <el-select v-model="searchForm.state" @change="currentPage = 1; inquiry()" clearable placeholder="请选择状态"
            @clear="currentPage = 1; inquiry()">
            <el-option v-for="(option, index) in stateOptions" :key="index" :label="option.label"
              :value="option.value" />
          </el-select>
        </el-form-item>
        <el-form-item label="" label-width="0">
          <el-button type="primary" size="small" @click="handleAdd">添加</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div class="dual_prevention_table_div">
      <el-table :data="tableData" style="width: 100%" height="100%">
        <el-table-column prop="ONAME" label="风险分析对象" align='center' :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="HAZARD_COD" label="编码" align='center' :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="OTYPE" label="分类" align='center'>
          <template slot-scope="scope">
            <span v-if="scope.row.OTYPE === '0'">生产装置</span>
            <span v-if="scope.row.OTYPE === '1'">罐区</span>
          </template>
        </el-table-column>
        <el-table-column prop="OIFRISK" label="是否重大危险源" align='center'>
          <template slot-scope="scope">
            <span v-if="scope.row.OIFRISK === '0'">是</span>
            <span v-if="scope.row.OIFRISK === '1'">否</span>
          </template>
        </el-table-column>
        <el-table-column prop="HAZARD_DEP" label="责任部门" align='center' :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="CZ_HAZARD_PERSON" label="部门责任人" align='center' :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="NFC" label="NFC编码" align='center' :show-overflow-tooltip="true">
          <template slot-scope="scope">
            <span v-if="scope.row.ONAME === 'H2/CO深冷分离单元'">001</span>
            <span v-if="scope.row.ONAME === '123全厂应急事故池'">002</span>
            <span v-if="scope.row.ONAME === '225溴化锂机组'">003</span>
            <span v-if="scope.row.ONAME === '2140焦炉煤气除杂'">004</span>
            <span v-if="scope.row.ONAME === 'DMO合成'">005</span>
            <span v-if="scope.row.ONAME === '中间罐区'">006</span>
            <span v-if="scope.row.ONAME === '副产品罐区'">007</span>
            <span v-if="scope.row.ONAME === '气柜单元'">008</span>
            <span v-if="scope.row.ONAME === 'LNG罐区'">009</span>
            <span v-if="scope.row.ONAME === '2550液相加氢'">010</span>
          </template>
        </el-table-column>
        <el-table-column label="操作" width="400" fixed="right" align="center">
          <template slot-scope="scope">
            <CustomButton :onClick="() => handleEdit(scope.row)">编辑</CustomButton>
            <CustomButton :onClick="() => handleLook(scope.row)">详情</CustomButton>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div class="dual_prevention_footer_div" v-show="pageLength * 1 > 0">
      <el-pagination @size-change="handleSizeChange" background @current-change="handleCurrentChange"
        :current-page="currentPage" :page-sizes="pageSizes" :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper" :total="pageLength">
      </el-pagination>
    </div>
    <!-- 添加组件 -->
    <add-device ref="addDevice" @success="inquiry" />
    <!-- 编辑组件 -->
    <edit-device ref="editDevice" @success="inquiry" />
    <!-- 详情组件 -->
    <look-device ref="lookDevice" @success="inquiry" />
  </div>
</template>

<script>
import mixin from "@/mixins/index"
import CustomButton from "@/components/CustomButton/index.vue";
import AddDevice from './components/AddDevice.vue'
import EditDevice from './components/EditDevice.vue'
import LookDevice from './components/LookDevice.vue'

export default {
  mixins: [mixin],
  components: {
    CustomButton,
    AddDevice,
    EditDevice,
    LookDevice
  },
  data() {
    return {
      tableLoading: false,
      tableData: [],
      searchForm: {
        work_code: '',
        state: ''
      },
      stateOptions: [
        { label: '全部', value: '' },
        { label: '已提交', value: '1' },
        { label: '已审批', value: '2' },
        { label: '已驳回', value: '3' },
        { label: '已取消', value: '4' }
      ]
    }
  },
  methods: {
    inquiry() {
      this.tableLoading = true

    },
    handleAdd() {
      this.$refs.addDevice.show()
    },
    handleEdit(row) {
      this.$refs.editDevice.show(row)
    },
    handleLook(row) {
      this.$refs.lookDevice.show(row)
    }
  }

}
</script>

<style lang="scss" scoped>
@import '@/theme/scroll-bar.scss';

.dual_prevention_div {
  // background-color: red;
  // max-height: fit-content;
  height: calc(100vh - 120px);
  display: flex;
  background-color: #ffffff;
  flex-direction: column;
  // flex: 1;
  width: 100%;
  border: 1px solid #ebeef5;
  color: #303133;
  padding: 15px;

  .dual_prevention_query_div {
    width: 100%;
  }

  .dual_prevention_table_div {
    flex: 1;
    overflow: hidden;
    width: 100%;

    .el-table {
      flex: 1;
    }

    .el-table__inner-wrapper {
      position: relative;
      display: flex;
      flex-direction: column;
      height: 100%;
      flex-wrap: nowrap;
    }
  }

  .dual_prevention_footer_div {
    margin-top: 15px !important;
    width: 100%;
    height: 24px;
  }
}

.el-scrollbar .el-scrollbar__view .el-select-dropdown__item {
  height: auto;
  // padding: 0  ;/
}
</style>